import { resultSuccess, resultError, getRequestToken, requestParams } from '../_util';
import { MockMethod } from 'vite-plugin-mock';
import { createFakeUserList } from './user';

// single
const dashboardRoute = {
  path: '/dashboard',
  name: 'Dashboard',
  component: 'LAYOUT',
  redirect: '/dashboard/analysis',
  meta: {
    orderNo: 10,
    icon: 'ion:grid-outline',
    title: 'routes.dashboard.dashboard',
  },
  children: [
    {
      path: 'analysis',
      name: 'Analysis',
      component: '/dashboard/analysis/index.vue',
      meta: {
        // affix: true,
        title: 'routes.dashboard.analysis',
      },
    },
    {
      path: 'workbench',
      name: 'Workbench',
      component: '/dashboard/workbench/index.vue',
      meta: {
        title: 'routes.dashboard.workbench',
      },
    },
  ],
};

const backRoute = {
  path: 'back',
  name: 'PermissionBackDemo',
  meta: {
    title: 'routes.demo.permission.back',
  },

  children: [
    {
      path: 'page',
      name: 'BackAuthPage',
      component: '/demo/permission/back/index',
      meta: {
        title: 'routes.demo.permission.backPage',
      },
    },
    {
      path: 'btn',
      name: 'BackAuthBtn',
      component: '/demo/permission/back/Btn',
      meta: {
        title: 'routes.demo.permission.backBtn',
      },
    },
  ],
};

const authRoute = {
  path: '/permission',
  name: 'Permission',
  component: 'LAYOUT',
  redirect: '/permission/front/page',
  meta: {
    icon: 'carbon:user-role',
    title: 'routes.demo.permission.permission',
  },
  children: [backRoute],
};

const levelRoute = {
  path: '/level',
  name: 'Level',
  component: 'LAYOUT',
  redirect: '/level/menu1/menu1-1',
  meta: {
    icon: 'carbon:user-role',
    title: 'routes.demo.level.level',
  },

  children: [
    {
      path: 'menu1',
      name: 'Menu1Demo',
      meta: {
        title: 'Menu1',
      },
      children: [
        {
          path: 'menu1-1',
          name: 'Menu11Demo',
          meta: {
            title: 'Menu1-1',
          },
          children: [
            {
              path: 'menu1-1-1',
              name: 'Menu111Demo',
              component: '/demo/level/Menu111',
              meta: {
                title: 'Menu111',
              },
            },
          ],
        },
        {
          path: 'menu1-2',
          name: 'Menu12Demo',
          component: '/demo/level/Menu12',
          meta: {
            title: 'Menu1-2',
          },
        },
      ],
    },
    {
      path: 'menu2',
      name: 'Menu2Demo',
      component: '/demo/level/Menu2',
      meta: {
        title: 'Menu2',
      },
    },
  ],
};

const sysRoute = {
  path: '/system',
  name: 'System',
  component: 'LAYOUT',
  redirect: '/system/account',
  meta: {
    icon: 'ion:settings-outline',
    title: 'routes.system.moduleName',
  },
  children: [
    {
      path: 'account',
      name: 'AccountManagement',
      meta: {
        title: 'routes.system.account',
        ignoreKeepAlive: true,
      },
      component: '/system/account/index',
    },
    {
      path: 'account_detail/:id',
      name: 'AccountDetail',
      meta: {
        hideMenu: true,
        title: 'routes.system.account_detail',
        ignoreKeepAlive: true,
        showMenu: false,
        currentActiveMenu: '/system/account',
      },
      component: '/system/account/AccountDetail',
    },
    {
      path: 'role',
      name: 'RoleManagement',
      meta: {
        title: 'routes.system.role',
        ignoreKeepAlive: true,
      },
      component: '/system/role/index',
    },

    {
      path: 'menu',
      name: 'MenuManagement',
      meta: {
        title: 'routes.system.menu',
        ignoreKeepAlive: true,
      },
      component: '/system/menu/index',
    },
    {
      path: 'dept',
      name: 'DeptManagement',
      meta: {
        title: 'routes.system.dept',
        ignoreKeepAlive: true,
      },
      component: '/system/dept/index',
    },
    {
      path: 'post',
      name: 'PostManagement',
      meta: {
        title: 'routes.system.post',
        ignoreKeepAlive: true,
      },
      component: '/system/post/index.vue',
    },
    {
      path: 'dictionary',
      name: 'DictionaryManagement',
      meta: {
        title: 'routes.system.dictionary',
        ignoreKeepAlive: true,
      },
      component: '/system/dictionary/index.vue',
    },
    {
      path: 'changePassword',
      name: 'ChangePassword',
      meta: {
        title: 'routes.system.password',
        ignoreKeepAlive: true,
      },
      component: '/system/password/index',
    },
  ],
};

const linkRoute = {
  path: '/link',
  name: 'Link',
  component: 'LAYOUT',
  meta: {
    icon: 'ion:tv-outline',
    title: 'routes.demo.iframe.frame',
  },
  children: [
    {
      path: 'doc',
      name: 'Doc',
      meta: {
        title: 'routes.demo.iframe.doc',
        frameSrc: 'https://doc.vvbin.cn/',
      },
    },
    {
      path: 'https://doc.vvbin.cn/',
      name: 'DocExternal',
      component: 'LAYOUT',
      meta: {
        title: 'routes.demo.iframe.docExternal',
      },
    },
  ],
};

const cmsRoute = {
  path: '/cms',
  name: 'Cms',
  component: 'LAYOUT',
  redirect: '/cms/article/article',
  meta: {
    orderNo: 100,
    icon: 'ant-design:file-done-outlined',
    title: 'routes.cms.article.moduleName',
  },
  children: [
    {
      path: 'article',
      name: 'ArticlesManagement',
      meta: {
        title: 'routes.cms.article.article',
      },
      children: [
        {
          path: 'article',
          name: 'ArticleManagement',
          meta: {
            title: 'routes.cms.article.article',
            ignoreKeepAlive: false,
          },
          component: '/cms/article/article/index.vue',
        },
        {
          path: 'column',
          name: 'ColumnsManagement',
          meta: {
            title: 'routes.cms.article.column',
            ignoreKeepAlive: true,
          },
          component: '/cms/article/column/index.vue',
        },
        {
          path: 'grabsource',
          name: 'GrabSourceManagement',
          meta: {
            title: 'routes.cms.article.grabsource',
            ignoreKeepAlive: false,
          },
          component: '/cms/article/grabsource/index.vue',
        },
        {
          path: 'grabtemplate',
          name: 'GrabTemplateManagement',
          meta: {
            title: 'routes.cms.article.grabtemplate',
            ignoreKeepAlive: false,
          },
          component: '/cms/article/grabtemplate/index.vue',
        },
      ],
    },
    {
      path: 'noticeboard',
      name: 'NoticeBoardManagement',
      meta: {
        title: 'routes.cms.article.noticeboard',
        ignoreKeepAlive: true,
      },
      component: '/cms/noticeboard/index.vue',
    },
    {
      path: 'carousel',
      name: 'CarouselManagement',
      meta: {
        title: 'routes.cms.carousel.carousel',
        ignoreKeepAlive: false,
      },
      component: '/cms/carousel/index.vue',
    },
    {
      path: 'singlepage',
      name: 'SinglePageManagement',
      meta: {
        title: 'routes.cms.singlepage.singlepage',
        ignoreKeepAlive: false,
      },
      component: '/cms/singlepage/index.vue',
    },
    {
      path: 'ads',
      name: 'AdsManagement',
      meta: {
        title: 'routes.cms.ads.ads',
        ignoreKeepAlive: false,
      },
      component: '/cms/ads/index.vue',
    },

    {
      path: 'file',
      name: 'FileManagement',
      meta: {
        title: 'routes.cms.file.file',
        ignoreKeepAlive: false,
      },
      component: '/cms/file/file/index.vue',
    },
    {
      path: 'friendlylink',
      name: 'FriendlylinkManagement',
      meta: {
        title: 'routes.cms.friendlylink.moduleName',
      },
      children: [
        {
          path: 'friendlylink',
          name: 'FriendlylinksManagement',
          meta: {
            title: 'routes.cms.friendlylink.friendlylink',
            ignoreKeepAlive: false,
          },
          component: '/cms/friendlylink/friendlylink/index.vue',
        },
        {
          path: 'group',
          name: 'FriendlylinkGroupManagement',
          meta: {
            title: 'routes.cms.friendlylink.group',
            ignoreKeepAlive: true,
          },
          component: '/cms/friendlylink/group/index.vue',
        },
      ],
    },
  ],
};

const feedbackRoute = {
  path: '/feedback',
  name: 'Feedback',
  component: 'LAYOUT',
  redirect: '/feedback/feedback',
  meta: {
    // hideChildrenInMenu: true,
    orderNo: 108,
    icon: 'ant-design:comment-outlined',
    title: 'routes.feedback.moduleName',
  },
  children: [
    {
      path: 'feedback',
      name: 'FeedbacksManagement',
      meta: {
        orderNo: 108,
        title: 'routes.feedback.feedback',
        ignoreKeepAlive: false,
      },
      component: '/feedback/feedback/index.vue',
    },
    {
      path: 'group',
      name: 'FeedbackGroupManagement',
      meta: {
        title: 'routes.feedback.group',
        ignoreKeepAlive: true,
      },
      component: '/feedback/group/index.vue',
    },
  ],
};

const userRoute = {
  path: '/user',
  name: 'User',
  component: 'LAYOUT',
  redirect: '/user/user',
  meta: {
    hideChildrenInMenu: false,
    orderNo: 100,
    icon: 'ant-design:user-outlined',
    title: 'routes.user.moduleName',
  },
  children: [
    {
      path: 'user',
      name: 'UserManagement',
      meta: {
        orderNo: 100,
        icon: 'ant-design:user-outlined',
        title: 'routes.user.user',
        hideMenu: true,
        ignoreKeepAlive: false,
        currentActiveMenu: '/user',
      },
      component: '/user/user/index.vue',
    },
    {
      path: 'detail/:id',
      name: 'UserDetail',
      meta: {
        hideMenu: true,
        title: 'routes.system.account_detail',
        ignoreKeepAlive: true,
        currentActiveMenu: '/user',
      },
      component: '/user/user/UserDetail.vue',
    },
  ],
};

const orderRoute = {
  path: '/order',
  name: 'Order',
  component: 'LAYOUT',
  redirect: '/order/paid',
  meta: {
    // hideChildrenInMenu: true,
    orderNo: 102,
    icon: 'ant-design:money-collect-outlined',
    title: 'routes.order.moduleName',
  },
  children: [
    {
      path: 'paied',
      name: 'PaiedOrderManagement',
      meta: {
        orderNo: 102,
        title: 'routes.order.paied',
        ignoreKeepAlive: false,
        // currentActiveMenu: '/order',
      },
      component: '/order/order/index.vue',
    },
    {
      path: 'unpaid',
      name: 'UnPaidOrderManagement',
      meta: {
        orderNo: 102,
        title: 'routes.order.unpaid',
        ignoreKeepAlive: false,
        // currentActiveMenu: '/order',
      },
      component: '/order/order/index.vue',
    },
    {
      path: 'expired',
      name: '   ExpiredOrderManagement',
      meta: {
        orderNo: 102,
        title: 'routes.order.expired',
        ignoreKeepAlive: false,
        // currentActiveMenu: '/order',
      },
      component: '/order/order/index.vue',
    },
  ],
};

const shopRoute = {
  path: '/shop',
  name: 'Shop',
  component: 'LAYOUT',
  redirect: '/shop/shop',
  meta: {
    orderNo: 106,
    icon: 'ant-design:shop-filled',
    title: 'routes.shop.moduleName',
  },
  children: [
    {
      path: 'goods',
      name: 'GoodsManagement',
      meta: {
        title: 'routes.shop.goods',
        ignoreKeepAlive: true,
      },
      component: '/shop/goods/index.vue',
    },
    {
      path: 'goods/detail/:id',
      name: 'GoodsDetail',
      meta: {
        hideMenu: true,
        title: 'routes.cms.article.articledetail',
        ignoreKeepAlive: true,
        showMenu: false,
        currentActiveMenu: '/shop/goods',
      },
      component: '/shop/goods/GoodsDetail.vue',
    },
    {
      path: 'category',
      name: 'CategoryManagement',
      meta: {
        title: 'routes.shop.category',
        ignoreKeepAlive: true,
      },
      component: '/shop/category/index.vue',
    },
    {
      path: 'shop',
      name: 'ShopManagement',
      meta: {
        title: 'routes.shop.shop',
        ignoreKeepAlive: false,
      },
      component: '/shop/shop/index.vue',
    },
    {
      path: 'detail/:id',
      name: 'ShopDetail',
      meta: {
        hideMenu: true,
        title: 'routes.shop.shopdetail',
        ignoreKeepAlive: true,
        showMenu: false,
        currentActiveMenu: '/shop/shop',
      },
      component: '/shop/shop/ShopDetail.vue',
    },
    {
      path: 'brand',
      name: 'BrandManagement',
      meta: {
        title: 'routes.shop.brand',
        ignoreKeepAlive: true,
      },
      component: '/shop/brand/index.vue',
    },
  ],
};

const monitoringRoute = {
  path: '/monitoring',
  name: 'Monitoring',
  component: 'LAYOUT',
  redirect: '/monitoring/task',
  meta: {
    orderNo: 107,
    icon: 'ant-design:code-twotone',
    title: 'routes.monitoring.moduleName',
  },
  children: [
    {
      path: 'logs',
      name: 'Logs',
      meta: {
        title: 'routes.monitoring.logs.moduleName',
      },
      children: [
        {
          path: 'login',
          name: 'LoginLogManagement',
          meta: {
            title: 'routes.monitoring.logs.login',
            ignoreKeepAlive: true,
          },
          component: '/monitoring/logs/login/index.vue',
        },
        {
          path: 'operation',
          name: 'OperationLogManagement',
          meta: {
            title: 'routes.monitoring.logs.operation',
            ignoreKeepAlive: false,
          },
          component: '/monitoring/logs/operation/index.vue',
        },
        {
          path: 'tracelog',
          name: 'TraceLogManagement',
          meta: {
            title: 'routes.monitoring.logs.trace',
            ignoreKeepAlive: true,
          },
          component: '/monitoring/logs/tracelog/index.vue',
        },
      ],
    },
    //powerjob
    {
      // path: 'task',
      path: 'https://powerjob.cngot.com',
      name: 'TaskManagement',
      meta: {
        title: 'routes.monitoring.task.moduleName',
        // ignoreKeepAlive: true,
      },
      // component: '/monitoring/task/index.vue',
      component: 'IFrame',
    },
    {
      // path: 'apollo',
      path: 'https://apollo.cngot.com',
      name: 'Apollo',
      component: 'IFrame',
      meta: {
        title: 'routes.monitoring.tool.apollo',
      },
    },
    {
      // path: 'jenkins',
      path: 'https://jenkins.cngot.com',
      name: 'Jenkins',
      component: 'IFrame',
      meta: {
        // frameSrc: config.VITE_GLOB_JENKINS_URL,
        title: 'routes.monitoring.tool.jenkins',
      },
    },
    {
      // path: 'yearning',
      path: 'https://Yearning.cngot.com',
      name: 'Yearning',
      component: 'IFrame',
      meta: {
        // frameSrc: config.VITE_GLOB_YEARNING_URL,
        title: 'routes.monitoring.tool.yearning',
      },
    },
    {
      // path: 'yapi',
      path: 'https://yapi.cngot.com',
      name: 'Yapi',
      component: 'IFrame',
      meta: {
        // frameSrc: config.VITE_GLOB_YAPI_URL,
        title: 'routes.monitoring.tool.yapi',
      },
    },
  ],
};

const messageRoute = {
  path: '/message',
  name: 'Message',
  component: 'LAYOUT',
  redirect: '/message/task',
  meta: {
    orderNo: 107,
    icon: 'ant-design:notification-outlined',
    title: 'routes.message.moduleName',
  },
  children: [
    {
      path: 'sms',
      name: 'Sms',
      meta: {
        title: 'routes.message.sms.moduleName',
      },
      children: [
        {
          path: 'logs',
          name: 'Logs',
          meta: {
            title: 'routes.message.sms.logs',
            ignoreKeepAlive: false,
          },
          component: '/message/sms/logs.vue',
        },
        {
          path: 'template',
          name: 'Template',
          meta: {
            title: 'routes.message.sms.template',
            ignoreKeepAlive: false,
          },
          component: '/message/sms/index.vue',
        },
        {
          path: 'send',
          name: 'Send',
          meta: {
            title: 'routes.message.sms.send',
            ignoreKeepAlive: false,
          },
          component: '/message/sms/send.vue',
        },
      ],
    },
    {
      path: 'email',
      name: 'Email',
      meta: {
        title: 'routes.message.email.moduleName',
      },
      children: [
        {
          path: 'logs',
          name: 'Logs',
          meta: {
            title: 'routes.message.email.logs',
            ignoreKeepAlive: false,
          },
          component: '/message/email/logs.vue',
        },
        {
          path: 'template',
          name: 'Template',
          meta: {
            title: 'routes.message.email.template',
            ignoreKeepAlive: false,
          },
          component: '/message/email/index.vue',
        },
        {
          path: 'send',
          name: 'Send',
          meta: {
            title: 'routes.message.email.send',
            ignoreKeepAlive: false,
          },
          component: '/message/email/send.vue',
        },
      ],
    },
    {
      path: 'notice',
      name: 'NoticeManagement',
      meta: {
        title: 'routes.message.notice.moduleName',
      },
      children: [
        {
          path: 'notice',
          name: 'Notice',
          meta: {
            title: 'routes.message.notice.moduleName',
            ignoreKeepAlive: false,
          },
          component: '/message/notice/index.vue',
        },
        {
          path: 'send',
          name: 'Send',
          meta: {
            title: 'routes.message.notice.send',
            ignoreKeepAlive: false,
          },
          component: '/message/notice/send.vue',
        },
      ],
    },
  ],
};

export default [
  {
    url: '/mock/getMenuList',
    timeout: 1000,
    method: 'get',
    response: (request: requestParams) => {
      const token = getRequestToken(request);
      if (!token) {
        return resultError('Invalid token!');
      }
      const checkUser = createFakeUserList().find((item) => item.token === token);
      if (!checkUser) {
        return resultError('Invalid user token!');
      }
      const id = checkUser.userId;
      let menu: Object[];
      switch (id) {
        case '1':
          dashboardRoute.redirect = dashboardRoute.path + '/' + dashboardRoute.children[0].path;
          // menu = [dashboardRoute, authRoute, levelRoute, sysRoute, linkRoute];
          menu = [
            dashboardRoute,
            cmsRoute,
            userRoute,
            feedbackRoute,
            orderRoute,
            shopRoute,
            messageRoute,
            monitoringRoute,
            sysRoute,
          ];
          break;
        case '2':
          dashboardRoute.redirect = dashboardRoute.path + '/' + dashboardRoute.children[1].path;
          menu = [dashboardRoute, authRoute, levelRoute, linkRoute];
          break;
        default:
          menu = [];
      }

      return resultSuccess(menu);
    },
  },
] as unknown as MockMethod[];
